package eu.liquify.ui {
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.Sprite;
	public class Panel extends UIContainer {
		
		private var _padding:Number = 5;
		public var background:Boolean = true;
		
		public var stretchV:Boolean = true;
		
		protected var backgroundDisplay:Sprite = new Sprite();
		
		public function Panel(options:Object = null) {
			super(options);
			padding = _padding;
			addRawChild(backgroundDisplay);
			addRawChild(content);
			content.mouseEnabled = false;
		}
		
		public function get padding():Number { return _padding; }
		
		public function set padding(value:Number):void {
			_padding = value;
			content.x = padding;
			content.y = padding;
		}
		
		override public function resize():void {
			super.resize();
			for (var i:int = 0; i < content.numChildren; i++) {
				var d:DisplayObject = content.getChildAt(i);
				if (d is UIItem) {
					var item:UIItem = d as UIItem;
					item.resize();
				}
			}
			
			if (!fixedWidth) width = content.width+content.x*2;
			if (!fixedHeight) height = content.height+content.y*2;
			
			redraw();
		}
		
		protected function redraw():void {
			var g:Graphics = backgroundDisplay.graphics;
			g.clear();
			if (background) {
				g.lineStyle(1, 0xDDDDDD, 1, true);
				g.beginFill(0xF8F8FC);
			} else {
				g.beginFill(0x000000, 0);
				//g.beginFill(0xFF0000);
			}
			g.drawRoundRect(0, 0, width-1, height-1, 6, 6);
		}
		
		override public function addChild(child:DisplayObject):DisplayObject {
			super.addChild(child);
			resize();
			return child;
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject {
			super.removeChild(child);
			resize();
			return child;
		}
		
	}

}